import { Tabs } from 'antd';
import { notification } from 'antd';
import { useOrder } from "../../hook/order.js"
//eslint-disable-next-line
import Indent from "../../api/indent";
import { useEffect } from 'react';
import All from "./all";
const { TabPane } = Tabs;
// 信息提示框
const openNotificationWithIcon = type => {
    notification[type]({
        message: '还未选择自提点',
        placement: "topLeft",
        description:
            '请选择自提点',
    });
};
// eslint-disable-next-line
export default () => {
    const [rows, genre, { order, State }] = useOrder();
    // 向后台请求订单数据
    // order();
    useEffect( () => {
        async function fetchData() {
            await order()
        }
        fetchData();
    }, [genre])
    console.log(rows);
    // 修改订单状态
    const states = async (Id) => {
        const data = await Indent.put({ Id })
        order();
        console.log(data);
    };
    // 选择请求订单类型
    function callback(key) {
        State(key)
    };

    // 判断是否有自提点
    const address = async (userId) => {
        const data = await Indent.address({ userId });
        console.log(data);
        if (data === []) {
            console.log("有");
        } else {
            openNotificationWithIcon('info')
        }
    }
    // 删除订单
    const deleteId = async (Id) => {
        const data = await Indent.deleteId({ Id });
        console.log(data);
        order();
    }

    // 新增订单
    const add = (userId, information, total, time, state) => {
        const data = Indent.postAdd({ userId, information, total, time, state });
        console.log(data);
    }
    return (
        <div style={{ width: "1100px", margin: "30px 0 0 60px" }}>
            <Tabs defaultActiveKey="全部订单" onChange={callback}>
                <TabPane tab="全部订单" key="全部订单">
                    <All rows={rows} deleteId={deleteId} states={states} />
                </TabPane>
                <TabPane tab="待发货" key="待发货">
                    <All rows={rows} deleteId={deleteId} states={states} />
                </TabPane>
                <TabPane tab="待收货" key="待收货">
                    <All rows={rows} deleteId={deleteId} states={states} />
                </TabPane>
                <TabPane tab="已完成" key="已完成">
                    <All rows={rows} deleteId={deleteId} states={states} />
                </TabPane>
            </Tabs>
        </div>)

}
